package com.c6906.vdam.das.schedule;

import com.c6906.vdam.das.config.DasOpenStatus;
import com.c6906.vdam.das.service.AreaCheckService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@EnableConfigurationProperties({DasOpenStatus.class})
public class FenceSync {

    private static final Logger logger = LoggerFactory.getLogger(FenceSync.class);

    @Resource
    DasOpenStatus openStatus;
    @Resource
    AreaCheckService areaCheckService;

    /**
     * 每十分钟更新禁区数据到redis中
     */
    @Scheduled(cron = "0 10 * * * ?")
    public void updateRedis() {
        if (openStatus.isOpenStatus() && openStatus.isOpenLastGpsToRedis()) {
            logger.info("【禁区同步】开始更新禁区数据到redis中");
            areaCheckService.initFunctionalArea();
            logger.info("【禁区同步】结束更新禁区数据到redis中");
        }
    }
}
